﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <div>
        <form>
            <input type="file" name="BigFile" value="" />
            <input type="button" value="上传" onclick="uploadFileInChunks(document.querySelector('input[type=file]').files[0])" />
        </form>
        
    </div>

    <script>
        async function uploadFileInChunks(file) {
            const CHUNK_SIZE = 5 * 1024 * 1024; // 5MB
            const totalChunks = Math.ceil(file.size / CHUNK_SIZE);

            for (let i = 0; i < totalChunks; i++) {
                const start = i * CHUNK_SIZE;
                const end = Math.min(start + CHUNK_SIZE, file.size);
                const chunk = file.slice(start, end);

                const formData = new FormData();
                formData.append('file', chunk);
                formData.append('fileName', file.name);
                formData.append('chunkIndex', i);
                formData.append('totalChunks', totalChunks);
                formData.append('totalSize', file.size);

                // 发送分块到服务器
                const response = await fetch('/api/BigFileUpload', {
                    method: 'POST',
                    body: formData
                });

                if (!response.ok) {
                    throw new Error(`上传失败: ${response.statusText}`);
                }
            }
        }
    </script>
</body>
</html>